import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../widgets/text_button.dart';
import '../../widgets/yz_text.dart';
import 'transform_lower_to_upper_controller.dart';

class TransformLowerToUpperPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<TransformLowerToUpperController>(
        init: TransformLowerToUpperController(),
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(
              title: Text('小写转大写'),
            ),
            body: Container(
                height: windowHeight,
                margin: EdgeInsets.symmetric(horizontal: 15),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Column(
                      children: [
                        MyTextField(
                          controller: controller.textEditingController,
                          width: 300,
                        ),
                      ],
                    ),
                    Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        SizedBox(
                          height: 10,
                        ),
                        _textButton('小写转大写', controller, onPressed: () {
                          controller.transform();
                        }),
                        SizedBox(
                          height: 15,
                        ),
                        _textButton('大写转小写', controller, onPressed: () {
                          controller.transform(type: 1);
                        }),
                      ],
                    ),
                    Expanded(
                        child: Container(
                      height: windowHeight * 0.8,
                      margin: EdgeInsets.only(top: 10),
                      padding: EdgeInsets.only(top: 10),
                      child: TextField(
                        controller: controller.codeTextEditingController,
                        readOnly: true,
                        decoration: InputDecoration(
                          border: const OutlineInputBorder(),
                        ),
                        maxLines: null,
                        style: TextStyle(color: Colors.green),
                      ),
                    ))
                  ],
                )),
          );
        });
  }

  _textButton(String text, TransformLowerToUpperController controller,
      {double width = 90, Function? onPressed}) {
    return Container(
        width: width,
        margin: EdgeInsets.only(left: 15, right: 20),
        alignment: Alignment.center,
        child: MyTextButton(
            text: text,
            confirm: () {
              onPressed?.call();
            },
            backgroundColor: Colors.deepPurpleAccent,
            textStyle: TextStyle(color: Colors.white, fontSize: 13)));
  }
}
